package nGui;

class Manager
{
	public function new()
	{
		ngui_init();
	}

	public function close()
	{
		ngui_close();
	}

	public function loop()
	{
		ngui_main_loop();
	}

	public function getText( title : String, text : String )
	{
		return ngui_get_text( untyped title.__s, untyped text.__s );
	}

	public function getFile( filter : String )
	{
		return ngui_get_file( untyped filter.__s );
	}

	public function alarm( title : String, message : String, b1 : String, ?b2 : String, ?b3 : String ) : Int
	{
		return ngui_alarm( untyped title.__s, untyped message.__s, untyped b1.__s, if (b2 == null) null else untyped b2.__s, if (b3 == null) null else untyped b3.__s );
	}

	public function appendItem( container : Void, item : Void )
	{
		ngui_append_element( container, item );
	}
	
	public static function amap<A,B>( a : Array<A>, f : A -> B ) : Array<B>
	{
		var b = new Array();
		for ( x in a )
			b.push( f( x ) );
		return b;
	}
	
	public static function getScreensize() : Array<Int>
	{
		var ss : String = neko.Lib.nekoToHaxe( ngui_get_screensize() );
		var ssa = ss.toLowerCase().split("x");
		return amap( ssa, Std.parseInt );
	}

	static var ngui_init = neko.Lib.load("nGui","ngui_init",0);
	static var ngui_close = neko.Lib.load("nGui","ngui_init",0);
	static var ngui_main_loop = neko.Lib.load("nGui","ngui_main_loop",0);
	static var ngui_append_element = neko.Lib.load("nGui","ngui_append_element",2);
	static var ngui_alarm = neko.Lib.load("nGui","ngui_element_alarm",5);
	static var ngui_get_text = neko.Lib.load("nGui","ngui_element_get_text",2);
	static var ngui_get_file = neko.Lib.load("nGui","ngui_element_get_file",1);
	static var ngui_get_screensize = neko.Lib.load("nGui","ngui_get_screensize",0);

}